package com.corpgovernment.organization.mapper;


import com.corpgovernment.organization.common.mybatis.TkMapper;
import com.corpgovernment.organization.dto.ListEmployeeQuery;
import com.corpgovernment.organization.dto.OrgUserInfoPk;
import com.corpgovernment.organization.entity.db.MbOrgEmployeeInfo;
import com.ctrip.corp.obt.generic.notification.annotation.InfoChange;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * MbOrgEmployeeInfoMapper数据库操作接口类
 **/
@Repository
@org.apache.ibatis.annotations.Mapper
public interface MbOrgEmployeeMapper extends TkMapper<MbOrgEmployeeInfo> {

    /**
     * 批量获取前台员工
     *
     * @param ids
     * @return
     */
    List<MbOrgEmployeeInfo> listByUids(@Param("uids") Collection<String> ids);

    /**
     * 根据角色Id批量获取用户信息
     * @param roleIds
     * @return
     */
    List<MbOrgEmployeeInfo> listByRoleIds(@Param("roleIds") Collection<Long> roleIds);
    List<MbOrgEmployeeInfo> selectByUid(@Param("uid") String uid);
    /**
     * 批量获取这些uids对应的前台员工，并且满足其他任意条件
     * 
     * @param uids 员工uid，未传则不筛选
     * @param phone 员工电话号码，精确匹配，未传则不筛选
     * @param email 员工邮箱，精确匹配，未传则不筛选
     */
    List<MbOrgEmployeeInfo> listAllByUidsAndAnyParam(@Param("uids") Collection<String> uids,
        @Param("phone") String phone, @Param("email") String email);

    /**
     * 批量获取前台员工
     *
     * @param uid
     * @return
     */
    MbOrgEmployeeInfo findByUid(@Param("uid") String uid);

    /**
     * 批量获取前台员工
     *
     * @param id
     * @return
     */
    MbOrgEmployeeInfo findById(@Param("id") Long id);

    /**
     * 批量查询后台用户
     *
     * @param uids
     * @return
     */
    List<MbOrgEmployeeInfo> listBackgroundByUids(@Param("uids") List<String> uids);

    /**
     * 批量获取前后台员工
     *
     * @param ids
     * @return
     */
    List<MbOrgEmployeeInfo> listByUidsAllPlat(@Param("uids") Collection<String> ids);

    /**
     * 根据职级查找前台员工（操作时间倒序）
     *
     * @param postId
     * @return
     */
    List<MbOrgEmployeeInfo> listByPostIdDesc(@Param("postId") Long postId);

    /**
     * 根据职级或者uid查找前台员工（操作时间倒序）
     *
     * @param postId
     * @return
     */
    List<MbOrgEmployeeInfo> listPageByPostIdOrUid(@Param("postId") Long postId, @Param("uid") String uid,@Param("orgIds")List<String> orgIds);

    /**
     * 根据职级查找前台员工
     *
     * @param postId
     * @return
     */
    List<MbOrgEmployeeInfo> listByPostId(@Param("postId") Long postId);

    /**
     * 根据职级或者uid查找前台员工
     *
     * @param postId
     * @return
     */
    List<MbOrgEmployeeInfo> listByPostIdOrUid(@Param("postId") Long postId, @Param("uid") String uid);

    /**
     * 根据uid、组织ID，模糊搜索前台员工
     *
     * @param uids
     * @param orgIds
     * @return
     */
    List<MbOrgEmployeeInfo> fuzzyByUidsAndOrgIds(@Param("uids") List<String> uids, @Param("orgIds") List<String> orgIds, @Param("status") Integer status);

    /**
     * 根据名字、手机号、组织是否启用，模糊搜索前台员工
     *
     * @param keyword
     * @param orgValid
     * @return
     */
    List<MbOrgEmployeeInfo> fuzzyByNameAndPhoneAndValid(@Param("keyword") String keyword, @Param("orgValid") Boolean orgValid,@Param("orgIds")List<String> orgIds);

    /**
     * 更新用户信息
     *
     * @param mbOrgEmployeeInfo
     * @return
     */
    @InfoChange(group = "VALID_STAFF", identityExpression = "uid", clientMappingKeyExpressions = "mobilePhone")
    int updateEmployeeByUid(MbOrgEmployeeInfo mbOrgEmployeeInfo);

    /**
     * 根据用户ID删除用户
     *
     * @param uid 用户id
     * @return 影响行数
     */
    @InfoChange(group = "VALID_STAFF", identityExpression = "uid", clientMappingKeyExpressions = "mobilePhone")
    int deleteByUid(@Param("uid") String uid);


//    /**
//     * 清空岗位下所有员工
//     *
//     * @param postId 岗位id
//     * @return 影响行数
//     */
//    int clearPostEmployeeByPostId(@Param("postId") Long postId);


//    /**
//     * 模糊查询员工
//     *
//     * @param orgIds
//     * @param key
//     * @return
//     */
//    List<MbOrgEmployeeInfo> searchEmployeeInfoList(@Param("orgIds") List<String> orgIds, @Param("key") String key);

//    /**
//     * 根据名字、组织ID，模糊搜索员工
//     *
//     * @param orgIds
//     * @param name
//     * @return
//     */
//    List<MbOrgEmployeeInfo> fuzzyByNameAndOrgIds(@Param("orgIds") List<String> orgIds, @Param("name") String name);

//    /**
//     * 根据员工ID、名字、组织ID，模糊搜索后台员工
//     *
//     * @param key
//     * @param orgIds
//     * @return
//     */
//    List<MbOrgEmployeeInfo> fuzzyBackgroundByUidAndNameAndOrgIDs(@Param("key") String key, @Param("orgIds") List<String> orgIds);

//    /**
//     * 根据手机号、组织ID，模糊搜索前台员工
//     *
//     * @param employeePhone
//     * @param departmentList
//     * @param page
//     * @param pageSize
//     * @return
//     */
//    List<MbOrgEmployeeInfo> fuzzyByPhoneAndOrgIDs(@Param("employeePhone") String employeePhone, @Param("departmentList") List<String> departmentList, @Param("page") Integer page, @Param("pageSize") Integer pageSize);

//    /**
//     * 通过组织架构ids查询所有用户
//     *
//     * @param orgIds 组织架构ids
//     * @return 员工列表
//     */
//    List<MbOrgEmployeeInfo> listByOrgIds(@Param("orgIds") List<String> orgIds);
//
//    /**
//     * 通过组织架构ids查询所有后台用户
//     *
//     * @param orgIds 组织架构ids
//     * @return 员工列表
//     */
//    List<MbOrgEmployeeInfo> batchSelectAllBackgroundByOrgIds(@Param("orgIds") List<String> orgIds);

    List<MbOrgEmployeeInfo> listUnAuditEmployee(@Param("orgId") String orgId);

    List<MbOrgEmployeeInfo> listByPostIds(@Param("postIds") List<Long> postIds);

    int updatePhoneByUid(@Param("uid") String uid, @Param("phoneNum") String phoneNum);

    List<MbOrgEmployeeInfo> listByQuery(ListEmployeeQuery listEmployeeQuery);

    List<MbOrgEmployeeInfo> listByQueryAndOgrIds(@Param("uids") List<String> uids, @Param("orgIds") List<String> orgIds, @Param("roleId") Long roleId);

    List<MbOrgEmployeeInfo> listByPk(@Param("pkList") List<OrgUserInfoPk> pkList);

    List<MbOrgEmployeeInfo> findAllName();

    List<MbOrgEmployeeInfo> findAllNameAllPlat();

    List<MbOrgEmployeeInfo> findAllNameAndPhone();

    List<MbOrgEmployeeInfo> findAll();

    List<MbOrgEmployeeInfo> selectByOrgIds(@Param("orgIds") List<String> orgIds);

    MbOrgEmployeeInfo findEmpAndOrgByUid(@Param("uid") String uid);

    int updateEmailByUid(@Param("employeeInfo") MbOrgEmployeeInfo employeeInfo);

    int updateEmployeeTypeByIds(@Param("employeeType") Integer employeeType, @Param("ids") List<String> ids);

    /**
     * 根据mbOrgEmployeeInfo中的name进行模糊查询
     * @param mbOrgEmployeeInfo
     * @return
     */
    List<MbOrgEmployeeInfo> fuzzyByNameSecurity(MbOrgEmployeeInfo mbOrgEmployeeInfo);

    List<MbOrgEmployeeInfo> queryEmployeeWithPermission(@Param("orgIdSet") Set<String> orgIdSet);

    /**
     * 批量更新人员信息
     * @param mbOrgEmployeeInfoList
     * @return
     */
    int updateBatchSelective(List<MbOrgEmployeeInfo> mbOrgEmployeeInfoList);

    /**
     * 根据名称、uid、员工类型、手机号模糊搜索员工
     * @param name
     * @param uid
     * @param employeeType
     * @param mobilePhone
     * @return
     */
    List<MbOrgEmployeeInfo> listEmployeeByCondition(@Param("uid")String uid, @Param("employeeType") Integer employeeType, @Param("uidList")List<String> uidList);
}